<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015-5-27
 * Time: 10:43
 */
namespace zhtfrontend\controllers;

use zhtfrontend\models\datas\PtaProposal;
use zhtfrontend\components\bases\BaseController;
use yii\web\Response;
use common\components\extenders\AjaxObject;
use common\components\helpers\Fun;
use yii\web\BadRequestHttpException;
use yii\data\Pagination;
use yii\helpers\Json;
use doumiaoduo\buildform\BuildForm;

class ProposalController extends BaseController
{
    public function actionIndex(){
            $pageSize = isset($param['pageSize']) ? $param['pageSize'] : 12;
            $data = PtaProposal::find()->where(['states'=>0])->orderBy('id ASC');
            $pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $pageSize]);
            isset($param['page']) ? $pages->page = $param['page'] - 1 : 0;
            $model = $data->offset($pages->offset)->limit($pages->limit)->all();
            $array=Fun::asArray($model,['zhtfrontend_operate','customer_name']);

        return $this->render('index',['data'=>$array,'pages'=>$pages]);
    }


    public function actionShield()
    {
        $this->layout='@app/views/layouts/iframe.php';
        if(\Yii::$app->request->get('id')==null){
            throw new BadRequestHttpException(\Yii::t('zhtfrontend','信息不存在'),404);
        }
        $info=PtaProposal::findOne(\Yii::$app->request->get('id'));
        if($info===null){
            throw new BadRequestHttpException(\Yii::t('zhtfrontend','信息不存在'),404);
        }
        //$info->customer_id=$info->customer->name;
        $form=new BuildForm('@app/components/forms/proposalForm.php');
        $form->loadModel(['proposal'=>$info]);
        $form->setOptions('proposal','title',['disabled'=>'disabled']);
        $form->setOptions('proposal','content',['disabled'=>'disabled']);
        if( $form->loadData(\Yii::$app->request->post()) && $form->validate() ){
            $model=$form->getModel('proposal');
            $info->states=$model->states;
            if($info->save(false)){
                return $this->redirectMessage(\Yii::t('zhtfrontend','屏蔽处理完成'),Fun::url(['proposal/index']),'success');
            }
        }
        return $this->render('shield',['form'=>$form->render()]);
    }
}




